Array.prototype.binarySearch = function (item) {
  if (typeof item === 'undefined') return -1
  let low = 0
  let high = this.length -1
  while (low <= high) {
    const mid = Math.floor((low + high) / 2)
    const element = this[mid]
    if (element < item) {
      low = mid + 1
    } else if (element > item) {
      high = mid - 1
     } else {
      return mid
    }
  }
  return -1
}

const res = [0, 1 ,2, 3, 4, 5]
console.log(res.binarySearch(2))
